package com.mcxx.modules.miniSalvation.family.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.modules.miniSalvation.family.dao.read.BankReadDao;
import com.mcxx.modules.miniSalvation.family.dto.BankDTO;
import com.mcxx.modules.miniSalvation.family.dto.BankExcelDTO;
import com.mcxx.modules.miniSalvation.family.dto.BankExcelMinDTO;
import com.mcxx.modules.miniSalvation.family.entity.BankEntity;
import com.mcxx.modules.miniSalvation.family.param.BankParam;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.FailureCode;
import com.mcxx.util.IdCardUtil;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("bankReadService")
@TaTransactional(readOnly = true)
public class BankReadService extends BaseService {
    @Autowired
    private BankReadDao bankReadDao;


    public BankEntity getBankById(String id) {
        return bankReadDao.getBankById(id);
    }


    public Page getTempBankPage(BankParam param, PageParam pageParam) {
        bankReadDao.beginPager(pageParam);

        return bankReadDao.endPager(bankReadDao.getTempBankList(param));
    }


    public Page getBankPage(BankParam param, PageParam pageParam) {

        param.setOrderTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCX56" : "BAX21");
        param.setFamilyMainTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCF13" : "BAF01");
        bankReadDao.beginPager(pageParam);
        return bankReadDao.endPager(bankReadDao.getList(param));
    }


    public Page getBankPageMin(BankParam param, PageParam pageParam) {

//        param.setOrderTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCX56" : "BAX21");
//        param.setFamilyMainTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCF13" : "BAF01");
        bankReadDao.beginPager(pageParam);
        return bankReadDao.endPager(bankReadDao.getBankPageMin(param));
    }


    public BankEntity getBankByFamilyId(String familyId, String memberId, String businessType){
        return bankReadDao.getBankByFamilyId(familyId, memberId, businessType);
    }


    public List<BankEntity> getByIdCardAndBizType(String familyId) {
        return bankReadDao.getByIdCardAndBizType(familyId);
    }


    public List<BankEntity> getBankByMember(String memberId, String businessType){
        return bankReadDao.getBankByMember(memberId, businessType);
    }


    public List<BankEntity> getBankByfamilyId(String familyId, String businessType){
        return bankReadDao.getBankByfamilyId(familyId, businessType);
    }


    public BankEntity getBankByFamilyIdEdit(String familyId,String memberId, String businessType){
        return bankReadDao.getBankByFamilyIdEdit(familyId,memberId, businessType);
    }


    public void bankMemberIdCardCheck(String accountIdcard){
        if (CommonUtil.invalidArgs(accountIdcard) || !IdCardUtil.identityCardVerification(accountIdcard).getData()) {
            throw new BizException(FailureCode.ERR_10030);
        }







//            throw new BizException(FailureCode.ERR_10035.getCode(), "该身份证号为户主身份证");

    }

    public List<BankExcelDTO> exportBank(BankParam param){
        param.setOrderTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCX56" : "BAX21");
        param.setFamilyMainTableName(Constant.BusinessCode.LINSHI.equalsIgnoreCase(param.getBusinessType()) ? "BCF13" : "BAF01");
        return bankReadDao.exportBank(param);
    }

    public List<BankExcelMinDTO> exportBankMin(BankParam param){
        return bankReadDao.exportBankMin(param);
    }


    public List<BankEntity> getBankByApplyIdCardAndBizType(String applyIdCard, String bizCode) {
        List<BankEntity> rst = bankReadDao.getBankByApplyIdCardAndBizType(applyIdCard,bizCode );



        return rst;
    }
}
